{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">客源列管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"
                   data-auth-add="{:$auth->check('source/add')}"
                   data-auth-edit="{:$auth->check('source/edit')}"
                   data-auth-delete="{:$auth->check('source/del')}"
                   data-auth-recyclebin="{:$auth->check('source/recyclebin')}"
            ></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['yznTable', 'table', 'laytpl', 'yzn', 'notice', 'element', 'dropdown', 'form', 'yznUpload'], function () {
        var table = layui.yznTable;
        var yznUpload = layui.yznUpload;
        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: '{:url("add")}',
            edit_url: '{:url("edit")}',
            delete_url: '{:url("del")}',
            modify_url: "{:url('multi')}",
            recyclebin_url: "{:url('recyclebin')}",
        };

        table.render({
            init: init,
            toolbar: ['refresh', 'add','delete', 'recyclebin',
                [{
                    html: '<a id="faupload-addon" class="layui-btn layui-btn-sm faupload" data-type="file"   data-chunking="false"  data-multiple="false"><i class="iconfont icon-upload-fill"></i>&nbsp;导入</a>'
                }
                ],
            ],

            url: '{:url("index")}',
            cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'weigh', align: 'center', width: 80, title: '排序', edit: 'text'},

                    {field: 'id', align: 'center', title: 'ID', minWidth: 80, search: false},
                    {
                        field: 'company_name',
                        align: 'center',
                        title: '公司名称',
                        searchOp: 'LIKE',
                        minWidth: 130
                    },
                    {field: 'phone', align: 'center', title: '联系电话', searchOp: 'LIKE', minWidth: 130},
                    {
                        field: 'status',
                        align: 'center',
                        width: 120,
                        title: '状态',
                        unresize: true,
                        templet: yznTable.formatter.switch,
                        tips: "显示|隐藏",
                        selectList: {0: '冻结', 1: '正常'},
                    },
                    {
                        field: 'create_time',
                        title: '创建时间',

                        minWidth: 80,
                        width: 180,
                        search: false,
                        templet: yznTable.formatter.datetime
                    },
                    {
                        field: 'update_time',
                        title: '更新时间',
                        minWidth: 80,
                        width: 180,
                        search: false,
                        templet: yznTable.formatter.datetime
                    },
                    {
                        fixed: 'right',
                        width: 90,
                        field: 'operate',
                        title: '操作',
                        search: false,
                        templet: yznTable.formatter.tool,
                        operat: ['edit', 'delete']
                    }
                ]
            ],
            page: {},
            done: function (res, curr, count) {
                yznUpload.api.upload('.faupload', function (data, ret) {
                    var path = data.path;
                    if (path) {
                        yzn.request.post({
                            url: '{:url("sys_source/import")}',
                            data: {
                                path: path
                            }
                        }, function (data, res) {
                            yzn.msg.alert(res.msg,function (msg) {
                                window.location.reload();
                            });
                        });
                    } else {
                        yzn.msg.success('上传失败');
                    }

                });
            }

        });

        yznTable.bindevent();
    });
</script>
{/block}